<%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-logic" prefix="logic" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<html:html>
<head>	
	<link rel="stylesheet" type="text/css" href="<%= request.getContextPath() %>/css/sampleForm.css" />
	<link rel="stylesheet" type="text/css" href="<%= request.getContextPath() %>/css/me.css" />	
	<link rel="stylesheet" type="text/css" href="<%= request.getContextPath() %>/common/css/help/help.css" />
	<title>บันทึกใบซื้ออุปกรณ์, วัตถุดิบ (BCAPInvoice, BCAPInvoiceSub)</title>
	<script type='text/javascript' src='/ittl/dwr/interface/BCProjectService.js'></script>
  	<script type='text/javascript' src='/ittl/dwr/interface/BCItemService.js'></script>
	<script type='text/javascript' src='/ittl/dwr/interface/BCAPService.js'></script>
	<!-- 
  	<script type='text/javascript' src='/ittl/dwr/interface/ItemLocationService.js'></script>
  	 -->
  	  	
  	<script type='text/javascript' src='/ittl/dwr/interface/BCAPInvoiceService.js'></script>
  	<script type='text/javascript' src='/ittl/dwr/engine.js'></script>
  	<script type='text/javascript' src='/ittl/dwr/util.js'></script>

	<script type='text/javascript' src='<%= request.getContextPath() %>/css/autocomplete/lib/jquery.js' ></script>
	<script type='text/javascript' src='<%= request.getContextPath() %>/css/autocomplete/lib/jquery.bgiframe.min.js1' ></script>
	<script type='text/javascript' src='<%= request.getContextPath() %>/css/autocomplete/lib/jquery.ajaxQueue.js1' ></script>
	<script type='text/javascript' src='<%= request.getContextPath() %>/css/autocomplete/lib/thickbox-compressed.js1' ></script>
	<script type='text/javascript' src='<%= request.getContextPath() %>/css/autocomplete/lib/jquery.autocomplete.js' ></script>
	
	<script type='text/javascript' src='<%= request.getContextPath() %>/css/autocomplete/data/localdata.js' ></script>
	<script type='text/javascript' src='<%= request.getContextPath() %>/css/autocomplete/data/localdata2.js' ></script>
	<script type='text/javascript' src='<%= request.getContextPath() %>/css/autocomplete/data/codeOfBuyRequest.js' ></script>
	<script type='text/javascript' src='<%= request.getContextPath() %>/css/autocomplete/data/localdata31.js' ></script>
	<script type='text/javascript' src='<%= request.getContextPath() %>/css/autocomplete/data/localdataDepartment.js' ></script>
	<script type='text/javascript' src='<%= request.getContextPath() %>/css/autocomplete/data/localdataDepartmentName.js' ></script>
	<script type='text/javascript' src='<%= request.getContextPath() %>/css/autocomplete/data/apCodeName.js' ></script>
	<script type='text/javascript' src='<%= request.getContextPath() %>/css/autocomplete/data/apCode.js' ></script>
	
	
	<link rel="stylesheet" type="text/css" href="<%= request.getContextPath() %>/css/autocomplete/css/mainOLD.css" />
	<link rel="stylesheet" type="text/css" href="<%= request.getContextPath() %>/css/autocomplete/css/jquery.autocomplete.css" />
	<link rel="stylesheet" type="text/css" href="<%= request.getContextPath() %>/css/autocomplete/css/thickbox.css" />
 
 	<script type="text/javascript" src="<%= request.getContextPath() %>/stockRequest/jquery.validate.js" ></script>
 	<script type="text/javascript" src="<%= request.getContextPath() %>/stockRequest/jquery-1.4.2.min1.js" ></script>

<!-- start 
 
	<link type="text/css" href="<%= request.getContextPath() %>/jquery-ui-1.8/development-bundle/themes/base/jquery.ui.all.css" rel="stylesheet" />
	<link type="text/css" href="<%= request.getContextPath() %>/jquery-ui-1.8/development-bundle/demos/demos.css" rel="stylesheet" />
	  	
	<script type="text/javascript" src="<%= request.getContextPath() %>/jquery-ui-1.8/development-bundle/jquery-1.4.2.js"></script>
	<script type="text/javascript" src="<%= request.getContextPath() %>/jquery-ui-1.8/development-bundle/external/jquery.bgiframe-2.1.1.js"></script>			
	<script type="text/javascript" src="<%= request.getContextPath() %>/jquery-ui-1.8/development-bundle/ui/jquery.ui.core.js"></script>
	<script type="text/javascript" src="<%= request.getContextPath() %>/jquery-ui-1.8/development-bundle/ui/jquery.ui.widget.js"></script>
	<script type="text/javascript" src="<%= request.getContextPath() %>/jquery-ui-1.8/development-bundle/ui/jquery.ui.mouse.js"></script>
	<script type="text/javascript" src="<%= request.getContextPath() %>/jquery-ui-1.8/development-bundle/ui/jquery.ui.button.js"></script>
	<script type="text/javascript" src="<%= request.getContextPath() %>/jquery-ui-1.8/development-bundle/ui/jquery.ui.draggable.js"></script>
	<script type="text/javascript" src="<%= request.getContextPath() %>/jquery-ui-1.8/development-bundle/ui/jquery.ui.position.js"></script>
	<script type="text/javascript" src="<%= request.getContextPath() %>/jquery-ui-1.8/development-bundle/ui/jquery.ui.resizable.js"></script>
	<script type="text/javascript" src="<%= request.getContextPath() %>/jquery-ui-1.8/development-bundle/ui/jquery.ui.dialog.js"></script>
	<script type="text/javascript" src="<%= request.getContextPath() %>/jquery-ui-1.8/development-bundle/ui/jquery.effects.core.js"></script>
	<script type="text/javascript" src="<%= request.getContextPath() %>/jquery-ui-1.8/development-bundle/ui/jquery.ui.datepicker.js"></script>
	<script type="text/javascript" src="<%= request.getContextPath() %>/jquery-ui-1.8/development-bundle/ui/jquery.ui.autocomplete.js"></script>
			
-->
<!-- end -->

<!-- start add/remove  
	<script type="text/javascript" src='<%= request.getContextPath() %>/common/js/addremove/jquery-latest.pack.js'></script>	
-->	
	<script type="text/javascript" src='<%= request.getContextPath() %>/common/js/addremove/jquery.highlightFade.js'></script>
	<script type="text/javascript">
		
	var id = 1;	

	var idArray = new Array();
	for(i=0;i<=15;i++) {
		idArray[i] = 0;	
	}

	var max = false;
	
	function addFormField() {
		
		var countId = parseInt(document.getElementById("countId").value);
																									
		id = countId+1; 
		//alert("id="+id);
												
				var newInput = "<tr id='r"+id+"'>"+
									"<td><a href='#' onClick='removeFormField(\"#r" + id + "\","+id+"); return false;'>"+
										"<img src=\"<%=request.getContextPath() %>/common/images/remove.png\" width=\"24\" height=\"24\" alt=\"Remove\" /></a></td>"+									
									"<td><input type='hidden' name='lineNumber' value='"+id+"' id='lineNumber"+id+"' >"+									
							  			"<input type='text'   name='itemCode'   value='' id='itemCode"+id+"' size='15'"+
						  				          " onchange=\"getItem(document.getElementById('itemCode"+id+"').value,"+id+")\""+
						  				          " onblur=\"getItem(document.getElementById('itemCode"+id+"').value,"+id+")\""+
						  				          " style=\"align:right;width:100px\"/></td> "+
									"<td><a href=\"#\" target=\"name\" onclick=\"modalWinItem('/ittl/apinvoice/apinvoice2.do?mode=moreItemsShow&lineNumber="+id+"'); return false;\">ค้น</a></td>"+	
									"<td><input type='text'   name=\"itemName\" value=\"\" maxlength=\"200\" size=\"40\" id=\"itemName"+id+"\" />"+
									    "</td>"+
									"<td align=\"center\"><select name=\"unitCode\" value=\"\" id=\"unitCode"+id+"\" style=\"width:60px\" >"+																									
																"<option value=\"PCS\">Pcs.</option>"+
																"<option value=\"007\">Kgs.</option>"+
																"<option value=\"008\">Lbs.</option>"+
																"<option value=\"001\">Unit</option>"+
																"<option value=\"032\">BAHT</option>"+
																"<option value=\"Baht\">Baht</option>"+
																"<option value=\"Bales.\">Bales.</option>"+
																"<option value=\"BOOK\">BOOK</option>"+
																"<option value=\"BOOK.\">BOOK.</option>"+
																"<option value=\"038\">Bott</option>"+
																"<option value=\"BOX.\">BOX.</option>"+
																"<option value=\"CAN.\">CAN.</option>"+
																"<option value=\"039\">Doz</option>"+
																"<option value=\"040\">Drum</option>"+
																"<option value=\"GALL.\">GALL.</option>"+
																"<option value=\"030\">Items</option>"+
																"<option value=\"041\">Job</option>"+
																"<option value=\"JPY\">JPY</option>"+
																"<option value=\"014\">Kg/pack</option>"+
																"<option value=\"013\">Kg/กล่อง</option>"+
																"<option value=\"007\">Kgs.</option>"+
																"<option value=\"KGS.\">KGS.</option>"+
																"<option value=\"LBS.\">LBS.</option>"+
																"<option value=\"008\">Lbs.</option>"+
																"<option value=\"LBS..\">LBS..</option>"+
																"<option value=\"042\">Lit</option>"+
																"<option value=\"LTS.\">LTS.</option>"+
																"<option value=\"043\">Mtr</option>"+
																"<option value=\"MTR.\">MTR.</option>"+
																"<option value=\"037\">MTS</option>"+
																"<option value=\"006\">Pack</option>"+
																"<option value=\"044\">Pair</option>"+
																"<option value=\"036\">PCS</option>"+
																"<option value=\"PCS\">PCS.</option>"+
																"<option value=\"PCS.\">PCS.</option>"+
																"<option value=\"045\">Point</option>"+
																"<option value=\"035\">POUND</option>"+
																"<option value=\"025\">Pub/100 Yds.</option>"+
																"<option value=\"028\">Pub/26.5 Yds.</option>"+
																"<option value=\"024\">Pub/50 Yds.</option>"+
																"<option value=\"REAM.\">REAM.</option>"+
																"<option value=\"ROLL\">ROLL</option>"+
																"<option value=\"ROLL.\">ROLL.</option>"+
																"<option value=\"SETS.\">SETS.</option>"+
																"<option value=\"046\">Tab</option>"+
																"<option value=\"047\">Tank</option>"+
																"<option value=\"048\">Tin</option>"+
																"<option value=\"049\">Tube</option>"+
																"<option value=\"001\">Unit</option>"+
																"<option value=\"033\">USD</option>"+
																"<option value=\"USD\">USD</option>"+
																"<option value=\"050\">Volume</option>"+
																"<option value=\"023\">Yds.</option>"+
																"<option value=\"YDS.\">YDS.</option>"+
																"<option value=\"YEN\">YEN</option>"+
																"<option value=\"034\">YEN</option>"+
																"<option value=\"051\">กก.</option>"+
																"<option value=\"052\">กป.</option>"+
																"<option value=\"054\">กป.</option>"+
																"<option value=\"053\">กล.</option>"+
																"<option value=\"004\">กล่อง</option>"+
																"<option value=\"055\">ก้อน</option>"+
																"<option value=\"095\">แกลลอน</option>"+
																"<option value=\"056\">ขด</option>"+
																"<option value=\"057\">ขวด</option>"+
																"<option value=\"คน\">คน</option>"+
																"<option value=\"029\">ครั้ง</option>"+
																"<option value=\"020\">คัน</option>"+
																"<option value=\"059\">คิว  </option>"+
																"<option value=\"009\">คิว ฟุต</option>"+
																"<option value=\"058\">คู่</option>"+
																"<option value=\"019\">เครื่อง</option>"+
																"<option value=\"099\">โคม</option>"+
																"<option value=\"060\">งาน</option>"+
																"<option value=\"061\">จุด</option>"+
																"<option value=\"062\">ฉบับ</option>"+
																"<option value=\"063\">ชุด</option>"+
																"<option value=\"065\">ซอง</option>"+
																"<option value=\"066\">ดอก</option>"+
																"<option value=\"067\">ด้าม</option>"+
																"<option value=\"068\">ตลับ</option>"+
																"<option value=\"026\">ต่อเดือน</option>"+
																"<option value=\"070\">ตัน</option>"+
																"<option value=\"003\">ตัว</option>"+
																"<option value=\"015\">ตัว/กล่อง</option>"+
																"<option value=\"010\">ตารางเมตร</option>"+
																"<option value=\"069\">ตู้</option>"+
																"<option value=\"102\">ถัง</option>"+
																
																"<option value=\"071\">ถุง</option>"+
																"<option value=\"072\">ท่อ</option>"+
																"<option value=\"005\">ท่อน</option>"+
																"<option value=\"016\">ท่อน คิว ม.</option>"+
																"<option value=\"017\">ท่อน คิวฟุต.</option>"+
																"<option value=\"เที่ยว\">เที่ยว</option>"+
																"<option value=\"096\">แท่ง</option>"+
																"<option value=\"074\">บ่อ</option>"+
																"<option value=\"073\">บาน</option>"+
																"<option value=\"101\">ใบ</option>"+
																"<option value=\"075\">ปอนด์</option>"+
																"<option value=\"076\">ปิ๊บ</option>"+
																"<option value=\"077\">ผืน</option>"+
																"<option value=\"002\">แผ่น</option>"+
																"<option value=\"011\">แผ่น/กล่อง</option>"+
																"<option value=\"012\">แผ่น/ตารางเมตร</option>"+
																"<option value=\"078\">ฝา</option>"+
																"<option value=\"พวง\">พวง</option>"+
																"<option value=\"097\">แพ็ค</option>"+
																"<option value=\"098\">แฟ้ม</option>"+
																"<option value=\"079\">ม.</option>"+
																"<option value=\"081\">ม้วน</option>"+
																"<option value=\"080\">มัด</option>"+
																"<option value=\"092\">เมตร</option>"+
																"<option value=\"031\">รายการ</option>"+
																"<option value=\"082\">รีม</option>"+
																"<option value=\"086\">ล้อ</option>"+
																"<option value=\"085\">ลัง</option>"+
																"<option value=\"083\">ลำ</option>"+
																"<option value=\"027\">ลิตร</option>"+
																"<option value=\"084\">ลูก</option>"+
																"<option value=\"093\">เล่ม</option>"+
																"<option value=\"087\">วง</option>"+
																"<option value=\"088\">วัน</option>"+
																"<option value=\"094\">เส้น</option>"+
																"<option value=\"018\">หลอด</option>"+
																"<option value=\"021\">หลัง</option>"+
																"<option value=\"089\">หลัง</option>"+
																"<option value=\"091\">ห่อ</option>"+
																"<option value=\"064\">ห่อ</option>"+
																"<option value=\"090\">หัว</option>"+
																"<option value=\"100\">โหล</option>"+
																"<option value=\"022\">อัน</option>"+
																	        
							   							"</select>"+
							   							
									"</td>"+
									"<td><input type='text'   name=\"qty\" value=\"\" size=\"7\" id=\"qty"+id+"\" onchange=\"calLineItem("+id+");\" style=\"text-align:right;width:60px\"  />"+
									    "</td>"+		
									"<td><input type='text'   name=\"price\" value=\"\" size=\"7\" id=\"price"+id+"\" onchange=\"calLineItem("+id+");\" style=\"text-align:right;width:60px\" />"+
									    "</td>"+						
									"<td><input type='text'   name=\"lineItemDiscountAmount\" value=\"\" size=\"7\" id=\"lineItemDiscountAmount"+id+"\" onchange=\"calLineItem("+id+")\"	style=\"text-align:right;width:60px\"  />"+
										"</td>"+
									"<td><input type='text'   name=\"amount\" value=\"\" id=\"amount"+id+"\" size=\"10\" onchange=\"calUnitPrice("+id+")\" style=\"text-align:right;width:80px\" />"+
									
									"<input type='hidden'   name=\"stkReqNo\"  	value='new line item'  id=\"stkReqNo"+id+"\" />"+
										"<input type='hidden'   name=\"confirmNo\" 	value=''  id=\"confirmNo"+id+"\" />"+
								
										"<input type='hidden'   name=\"lineItem_whCode\" 		value='' 	id=\"lineItem_whCode"+id+"\" />"+
										"<input type='hidden'   name=\"lineItem_shelfCode\" 	value='' 	id=\"lineItem_shelfCode"+id+"\" />"+
								
										"<input type='hidden'   name=\"lineItem_statusReceive\"	value=''	id=\"lineItem_statusReceive"+id+"\" />"+
										"<input type='hidden'   name=\"lineItem_departCode\" 	value='' 	id=\"lineItem_departCode"+id+"\" />"+
										"<input type='hidden'   name=\"lineItem_projectCode\" 	value=''  	id=\"lineItem_projectCode"+id+"\" />"+
										"<input type='hidden'   name=\"lineItem_allocateCode\" 	value='' 	id=\"lineItem_allocateCode"+id+"\" />"+
										"<input type='hidden'   name=\"lineItem_myDescription\"	value=''	id=\"lineItem_myDescription"+id+"\" />"+
										"<input type='hidden'   name=\"lineItem_poRefNo\" 		value='' 	id=\"lineItem_poRefNo"+id+"\" />"+
										"<input type='hidden'   name=\"lineItem_netAmount\" 	value='' 	id=\"lineItem_netAmount"+id+"\" />"+
										"<input type='hidden'   name=\"lineItem_homeAmount\" 	value='' 	id=\"lineItem_homeAmount"+id+"\" />"+								
									"</td>"+				
									
									"<td><label id=\"lineItem_moreDetails"+id+"\">"+
											"<a href=\"#\" target=\"name\" onclick=\"modalWin('/ittl/apinvoice/apinvoice2.do?mode=moreDetailsShow&lineItem_whCode=&lineItem_shelfCode=&lineItem_statusReceive=&lineItem_departCode=&lineItem_projectCode=&lineItem_allocateCode=&lineItem_myDescription=&lineItem_poRefNo=&lineItem_netAmount=&lineItem_homeAmount=&lineNumber="+id+"'); return false;\">อื่นๆ</a>"+
										"</label>  </td>"+
									
								"</tr>";								
		$("#inputs").append(newInput); 
		$('#r' + id).highlightFade({
			speed:2000
		});
		document.getElementById("countId").value = id;																						  																												
								
	}
	
	function removeFormField(rid, id) {
//		var count = 0;
//		for (i=0; i<idArray.length; i++) {
//			if(idArray[i]>0) {
//				count++;
//			}
//		}		
//		if(count>1) {
	
		var answer = confirm('ยืนยันการลบข้อมูล');
		if(answer) {	
			$(rid).remove();
			$("#s"+id).remove();
			idArray[id-1] = 0;
		}
//		}else {
//			alert("กรุณาบันทึกข้อมูลอย่างน้อย 1 รายการ");
//		}
		
	}
		
	</script>
<!-- end add/remove  -->

<style type="text/css">
#form1 label.error {
	font-size: 1.0em;
	color: red;
}
</style>
 	
<script language="JavaScript">
 
function compareBuga() {
	return "buga22";
}

$.validator.addMethod("buga", function(value) {
	return value == compareBuga();
}, 'Please enter "buga"!');

$(document).ready(function() {
		
	$("#form1").validate({
					
		submitHandler: function() {
			alert("txt1="+document.getElementById("txt1").value);
			alert("submitted!22");
			//$('#dialog-confirm').dialog('open');
			form.submit();
		},
				
		rules: {
			txt1: "required",
			docNo1: "required",
			docDate1: "required",
			apCode1: "required",
			iTTL_deptPay: "required",
			projectCode1: "required",
			unitCode1:"required",
			unitCode2:"required",
			unitCode3:"required",
			unitCode4:"required",
			unitCode5:"required",
			unitCode6:"required",
			unitCode7:"required",
			unitCode8:"required",
			unitCode9:"required",
			unitCode10:"required",
			unitCode11:"required",
			unitCode12:"required",
			unitCode13:"required",
			unitCode14:"required",
			unitCode15:"required",
			unitCode16:"required",
			unitCode17:"required",
			unitCode18:"required",
			unitCode19:"required",
			unitCode20:"required"
		},
		messages: {
			txt1: "*",
			docNo1: "*",
			docDate1: "*",
			apCode1: "*",
			iTTL_deptPay: "*",
			projectCode1: "*",
			unitCode1:"required",
			unitCode2:"required",
			unitCode3:"required",
			unitCode4:"required",
			unitCode5:"required",
			unitCode6:"required",
			unitCode7:"required",
			unitCode8:"required",
			unitCode9:"required",
			unitCode10:"required",
			unitCode11:"required",
			unitCode12:"required",
			unitCode13:"required",
			unitCode14:"required",
			unitCode15:"required",
			unitCode16:"required",
			unitCode17:"required",
			unitCode18:"required",
			unitCode19:"required",
			unitCode20:"required"			
	
		},

		// the errorPlacement has to take the table layout into account
		errorPlacement: function(error, element) {
			//alert("errorPlacement");			
			if ( element.is(":radio") ) {
				alert("radio");
				error.appendTo( element.parent().next().next() );
			}else if ( element.is(":checkbox") ) {
				alert("checkbox");
				error.appendTo ( element.next() );
			}else {
				/*alert(element("#itemCode1"));
				if(element.is("#itemCode1")) {
					error.appendTo( "#qty1-error" );
				}else {
					error.appendTo( element.parent().next() );	
				}*/
				//error.insertAfter('#qty1-error');
				error.appendTo( element.parent().next() );
			}
		}		
	});
	

	$("#suggest1").focus().autocomplete(cities);
	
	$("#suggestProject").autocomplete(projects, {		
		max:30,
		minChars: 0,
		autoFill: true,
		mustMatch: true,
		matchContains: false,
		scrollHeight: 200
	});

	
	$("#departCode").autocomplete(departments, {		
		max:30,
		minChars: 0,
		autoFill: true,
		mustMatch: true,
		matchContains: false,
		scrollHeight: 200
	});
			
	$("#suggestDeptPay").autocomplete(departments, {		
		max:30,
		minChars: 0,
		autoFill: true,
		mustMatch: true,
		matchContains: false,
		scrollHeight: 200
	});
			
	$("#suggestCode1").autocomplete(codes, {
		max:30,
		minChars: 0,
		autoFill: true,
		mustMatch: true,
		matchContains: false,
		scrollHeight: 200				
	});
	

	$("#suggest4").autocomplete(emails, {
		minChars: 0,
		
		matchContains: true,
		autoFill: false,
		formatItem: function(row, i, max) {
			return i + "/" + max + ": \"" + row.name + "\" [" + row.to + "]";
		},
		formatMatch: function(row, i, max) {
			return row.name + " " + row.to;
		},
		formatResult: function(row) {
			return row.to;
		}
	});

	for(i=1;i<=15;i++) {
		$("#itemCode"+i+"old").autocomplete(itemsName, {
			minChars: 0,
			width: 400,
			max:50,
			mustMatch: true,
			matchContains: true,
			autoFill: false,
			formatItem: function(row, i, max) {
				return row.code + ": [" + row.name + "]";
			},
			formatMatch: function(row, i, max) {
				return row.code + ": [" + row.name + "]";
			},
			formatResult: function(row) {
				return row.code;
			}
		});
	}	
			
});

</script>  

<!--  ส่วนที่ 2 -->
<script language="JavaScript">
var inputNo;
var itemName = "";
var code;
var itemName;
var whCode;
var shelfCode;
var shelfName;

function getItem(var1,x) {
	inputNo = x;
	
	if (confirm('ต้องการดึงค่า \"ชื่อรายการ default\" ของ \n\nitemCode:'+document.getElementById('itemCode'+inputNo).value+' หรือไม่ ?')==true) {
		
		BCItemService.getItem( var1, loadinfo2 );
	}	  
}

<!--  ส่วนที่ 3 -->
function loadinfo2(item)
{
	code 	  = item.code;
	if(code=="") {
		alert("ไม่พบ "+document.getElementById('itemCode'+inputNo).value + "  ในระบบ");
		dwr.util.setValue("itemCode"+inputNo, "");
		document.getElementById('itemCode'+inputNo).focus();
	}else {
		itemName  = item.itemName;
		
		whCode 	  = "10";//item.whCode;
		shelfCode = "10";//item.shelfCode;
		shelfName = item.shelfName;
		unitCode = item.unitCode;
		unitName = item.unitName;
		ittl_row = item.ittl_row;
		ittl_shelf = item.ittl_shelf;
		
		dwr.util.setValue("itemCode"+inputNo, code);
		dwr.util.setValue("itemName"+inputNo, itemName);
		dwr.util.setValue("whCode"+inputNo, whCode);			
		dwr.util.setValue("unitCode"+inputNo, unitCode);
		dwr.util.setValue("unitName"+inputNo, unitName);			
		dwr.util.setValue("ittl_row"+inputNo, ittl_row);
		dwr.util.setValue("ittl_shelf"+inputNo, ittl_shelf);
	}											
}

function getData(var1,x) {	
	inputNo = x;
	ItemLocationService.getData( var1, loadinfo );	  
}

//<!--  ส่วนที่ 3 -->
function loadinfo(data)
{
	code 	  = data.code;
	itemName  = data.name1;
	whCode 	  = data.whCode;
	shelfCode = data.shelfCode;
	shelfName = data.shelfName;
	unitCode = data.unitCode;
	unitName = data.unitName;

	ittl_row = data.ittl_row;
	ittl_shelf = data.ittl_shelf;
	
	
		dwr.util.setValue("itemCode"+inputNo, code);
			dwr.util.setValue("itemName"+inputNo, itemName);
			dwr.util.setValue("whCode"+inputNo, whCode);			
			dwr.util.setValue("unitCode"+inputNo, unitCode);
			dwr.util.setValue("unitName"+inputNo, unitName);
			//redirectN(0, document.getElementById('shCode1'));
			//redirectN(0, document.getElementById('shCode5'));//ใช้ document.form1.shelfCode5 จะทำงานได้บน IE แต่ไม่ไได้บน FF
			dwr.util.setValue("ittl_row"+inputNo, ittl_row);
			dwr.util.setValue("ittl_shelf"+inputNo, ittl_shelf);
											
}

function redirectN(x, tempN){
	
	var groupsN=5;//document.form1.shelfCode1.options.length
	var groupN=new Array(groupsN);
	for (i=0; i<groupsN; i++)
		groupN[i]=new Array();

	//var tempN=document.form1.shelfCode1;	
	//alert("tempN.options.length-1 = "+(tempN.options.length-1));
	for (m=tempN.options.length-1;m>=0;m--) {
		//alert(tempN.options[m]);
		tempN.options[m]=null;
	}
	
	if(shelfName != null) {
		for (i=0; i<shelfName.length; i++) {
			groupN[0][i]=new Option(shelfName[i], shelfCode[i]);
		}
					
		for (i=0;i<groupN[x].length;i++){
			text = groupN[x][i].value+":"+groupN[x][i].text;
			tempN.options[i]=new Option(text,groupN[x][i].value);
		}
		tempN.options[0].selected=true;
	}
}
</script>
<!--  ส่วนที่ 2 -->
<script language="JavaScript">

function getAP() {
	//alert("bcproject"+form1.projectCode.value); ใช้ใน ff ไม่ผ่าน			
	BCAPService.getAP( document.getElementById("apCode").value, loadinfoAP );			  
}

//<!--  ส่วนที่ 3 -->
function loadinfoAP(ap){
	if(ap.name1!=null) {
		dwr.util.setValue("apName", ap.name1);
	}else {
		alert("ไม่พบรหัสเจ้าหนี้ :"+document.getElementById("apCode").value+" \n\n\nกรุณาตรวจสอบรหัสเจ้าหนี้อีกครั้ง");
		//document.getElementById("apCode").focus();
		dwr.util.setValue("apName", "");
	}
				     
}
</script>
<!--  ส่วนที่ 2 -->
<script language="JavaScript">

function getProject() {
	//alert("bcproject"+form1.projectCode.value); ใช้ใน ff ไม่ผ่าน			
	BCProjectService.getProject( document.getElementById("suggestProject").value, loadinfoProject );			  
}

//<!--  ส่วนที่ 3 -->
function loadinfoProject(project){		
	//dwr.util.setValue("projectCode", project.name);
	dwr.util.setValue("projectName", project.name);			     
}
</script>

<!--  ส่วนที่ 2 -->
<script language="JavaScript">

function getMaxDocNo() {
	//alert("aa");	
	var docNo = document.getElementById("docNo");			
	BCAPInvoiceService.getMaxDocNo(docNo+"-", loadinfoDocNo);			  
}

//<!--  ส่วนที่ 3 -->
function loadinfoDocNo(maxDocNo){		
	
	dwr.util.setValue("docNo", maxDocNo.docNo);

				     
}
</script>	

	<link type="text/css" href="<%= request.getContextPath() %>/css/datepicker/css/ui.all.css" rel="stylesheet" /> 	
	<script type="text/javascript" src="<%= request.getContextPath() %>/css/datepicker/lib/jquery-ui-1.5.3.min.js"></script>	
	<script type="text/javascript">
		$(document).ready(function(){
    			$("#docDate").datepicker({ altField: 'input#docDate', altFormat: 'yy-mm-dd' });
    			$("#taxDate").datepicker({ altField: 'input#taxDate', altFormat: 'yy-mm-dd' });
    			$("#statementDate").datepicker({ altField: 'input#statementDate', altFormat: 'yy-mm-dd' });
    			$("#dueDate").datepicker({ altField: 'input#dueDate', altFormat: 'yy-mm-dd' });
    			
  		});
	</script>

<script type="text/javascript" language="JavaScript">
	var sumOfLineItemAmount = new Array();
	var sumOfAmount = 0;
	var qty = 0;
	var price = 0;
	var disAmt =0;
	var discountAmount = 0;
	var taxAmount = 0;
	
	var qtyArray = new Array();
	for(var i=1; i<=50; i++) {
		qtyArray[i]=0;
		sumOfLineItemAmount[i] = 0;
	}
	
function calUnitPriceold(id) {
	
	qty = document.getElementById('qty'+id).value;	
	disAmt = document.getElementById('lineItemDiscountAmount'+id).value;
	if(disAmt=="") {
		disAmt = 0;
	}	
		
	sumOfAmount -= sumOfLineItemAmount[id];

	sumOfLineItemAmount[id] = document.getElementById('amount'+id).value;
	sumOfAmount = sumOfAmount*1+sumOfLineItemAmount[id]*1;

	document.getElementById('lineItemDiscountAmount'+id).value =0;
	//alert(document.getElementById('lineItemDiscountAmount'+id).value);
	
	document.getElementById('price'+id).value = parseFloat(sumOfLineItemAmount[id]/qty).toFixed(2);

	var discountAmount = document.getElementById('discountAmount').value;

//	document.getElementById('discountAmount').value = parseFloat("0").toFixed(2);
	document.getElementById('sumOfItemAmount').value = sumOfAmount;
	
	var vat = 0;
	if(document.getElementById('taxNo').value!="" || document.getElementById('billType').value==3) {
		vat = calTaxAmount();
//		alert(vat);
		document.getElementById('taxAmount').value = parseFloat(vat).toFixed(2);
	}else {
		document.getElementById('taxAmount').value = parseFloat("0").toFixed(2);;
	}

	
	document.getElementById('totalAmount').value = parseFloat(sumOfAmount-discountAmount+1*vat).toFixed(2);
	document.getElementById('netAmount').value = parseFloat(sumOfAmount-discountAmount+1*vat).toFixed(2);

//	if(document.getElementById('docNo').value.substring(0,3)=="BCS") {
//		document.getElementById('payAmount').value = parseFloat(sumOfAmount-discountAmount+1*vat).toFixed(2);
//		document.getElementById("refNo").value = "ST";
//	}else {
//		document.getElementById('payAmount').value = 0;
//		document.getElementById("refNo").value = "";
//	}
	//document.getElementById('lineItemDiscountAmount'+id).value=disAmt;			 
}

function calUnitPrice(id) {
	
	qty = document.getElementById('qty'+id).value;	
	price = document.getElementById('price'+id).value;
	disAmt = document.getElementById('lineItemDiscountAmount'+id).value;
	
	//ถ้าข้อมูลส่วนลด เข้ามาแบบ %
	if(isNaN(disAmt)) {
		if(disAmt.charAt(disAmt.length-1)=="%")	{
			if(!isNaN(disAmt.substring(0, disAmt.length-1))) {
				disAmt = qty*price*parseFloat(disAmt.substring(0, disAmt.length-1))/100;	
			}
		}		
	}else if(disAmt=="") {
		disAmt = 0;
	}	

	line_amount= document.getElementById('amount'+id).value;

	if(line_amount==(qty*price-disAmt)) {
		return 
	}
			
	sumOfAmount -= sumOfLineItemAmount[id];

	sumOfLineItemAmount[id] = document.getElementById('amount'+id).value;
	sumOfAmount = sumOfAmount*1+sumOfLineItemAmount[id]*1;

	document.getElementById('lineItemDiscountAmount'+id).value =0;

	document.getElementById('price'+id).value = parseFloat(sumOfLineItemAmount[id]/qty).toFixed(2);

	var discountAmount = document.getElementById('discountAmount').value;

//	document.getElementById('discountAmount').value = parseFloat("0").toFixed(2);
	document.getElementById('sumOfItemAmount').value = sumOfAmount;
	
	var vat = 0;
	if(document.getElementById('taxNo').value!="" || document.getElementById('billType').value==3) {
		vat = calTaxAmount();
		document.getElementById('taxAmount').value = parseFloat(vat).toFixed(2);
	}else {
		document.getElementById('taxAmount').value = parseFloat("0").toFixed(2);;
	}

	document.getElementById('totalAmount').value = parseFloat(sumOfAmount-discountAmount+1*vat).toFixed(2);
	document.getElementById('netAmount').value = parseFloat(sumOfAmount-discountAmount+1*vat).toFixed(2);

//	if(document.getElementById('docNo').value.substring(0,3)=="BCS") {
//		document.getElementById('payAmount').value = parseFloat(sumOfAmount-discountAmount+1*vat).toFixed(2);
//		document.getElementById("refNo").value = "ST";
//	}else {
//		document.getElementById('payAmount').value = 0;
//		document.getElementById("refNo").value = "";
//	}			 
}

function calLineItem(id) {
	
	qty = document.getElementById('qty'+id).value;	
	price = document.getElementById('price'+id).value;
	disAmt = document.getElementById('lineItemDiscountAmount'+id).value;
	
	//ถ้าข้อมูลส่วนลด เข้ามาแบบ %
	if(isNaN(disAmt)) {
		if(disAmt.charAt(disAmt.length-1)=="%")	{				
//			alert(disAmt.charAt(disAmt.length-1));				
//			alert(disAmt.substring(0, disAmt.length-1));
			
			if(!isNaN(disAmt.substring(0, disAmt.length-1))) {
				disAmt = qty*price*parseFloat(disAmt.substring(0, disAmt.length-1))/100;	
			}
		}		
	}
	
	if(disAmt=="") {
		disAmt = 0;
	}
	
	
	sumOfLineItemAmount[id] = parseFloat(qty*price-disAmt).toFixed(2);
	
	document.getElementById('amount'+id).value = parseFloat(sumOfLineItemAmount[id]).toFixed(2);
	document.getElementById('lineItem_netAmount'+id).value = parseFloat(sumOfLineItemAmount[id]).toFixed(2);
	document.getElementById('lineItem_homeAmount'+id).value = parseFloat(sumOfLineItemAmount[id]).toFixed(2);

	
	sumOfAmount = calSumAmount();//sumOfAmount*1+sumOfLineItemAmount[id]*1;

	document.getElementById('discountAmount').value = parseFloat("0").toFixed(2);	
	document.getElementById('sumOfItemAmount').value = parseFloat(sumOfAmount).toFixed(2);

	//alert(document.getElementById('taxNo'));
	var vat = 0;
	if(document.getElementById('taxNo')!=null && 
			( document.getElementById('taxNo').value!="" || document.getElementById('billType').value==3 )) {
		vat = calTaxAmount();
		document.getElementById('taxAmount').value = parseFloat(vat).toFixed(2);
	}else {
		document.getElementById('taxAmount').value = parseFloat("0").toFixed(2);;
	}
	document.getElementById('totalAmount').value = parseFloat(sumOfAmount*1+vat*1).toFixed(2);
	document.getElementById('netAmount').value = parseFloat(sumOfAmount*1+vat*1).toFixed(2);		
	
//	if(document.getElementById('docNo').value.substring(0,3)=="BCS") {
//		document.getElementById('payAmount').value = document.getElementById('netAmount').value
//		document.getElementById("refNo").value = "ST";
//	}else {
//		document.getElementById('payAmount').value = 0;
//		document.getElementById("refNo").value = "";
//	}
	
	
	document.getElementById('price'+id).value = parseFloat(price).toFixed(2);
	
	if(!isNaN(document.getElementById('lineItemDiscountAmount'+id).value)) {
		document.getElementById('lineItemDiscountAmount'+id).value=parseFloat(disAmt).toFixed(2);
	}
//	alert("22");
//	alert(document.getElementById('taxType').options);
	calTaxType(document.getElementById('taxType').options);
	
}

function calTaxAmount() {
	sumOfItemAmount = 0;
	discountAmount = 0;
	if(document.getElementById('taxNo').value!="" ||
			document.getElementById('billType').value==3) {
		sumOfItemAmount = parseFloat(document.getElementById('sumOfItemAmount').value);

		if(document.getElementById('discountAmount').value!="") {
			discountAmount = parseFloat(document.getElementById('discountAmount').value);										
		}	
		var taxAmount = parseFloat((sumOfItemAmount-discountAmount)*0.07).toFixed(2);
		
		document.getElementById('taxAmount').value  = parseFloat(taxAmount).toFixed(2);
		document.getElementById('totalAmount').value= parseFloat(sumOfItemAmount*1+taxAmount*1-discountAmount).toFixed(2);
		document.getElementById('netAmount').value 	= parseFloat(sumOfItemAmount*1+taxAmount*1-discountAmount).toFixed(2);
		
//		if(document.getElementById('docNo').value.substring(0,3)=="BCS") {
//			document.getElementById('payAmount').value = document.getElementById('netAmount').value
//			document.getElementById("refNo").value = "ST";
//		}else {
//			document.getElementById('payAmount').value = 0;
//			document.getElementById("refNo").value = "";
//		}


									
	}else {
		if(document.getElementById('sumOfItemAmount').value!="") {
			sumOfItemAmount = parseFloat(document.getElementById('sumOfItemAmount').value);
		}
		if(document.getElementById('discountAmount').value!="") {
			discountAmount = parseFloat(document.getElementById('discountAmount').value);										
		}		
		document.getElementById('taxAmount').value  = parseFloat("0").toFixed(2);		
		document.getElementById('totalAmount').value= parseFloat(sumOfItemAmount*1-discountAmount).toFixed(2);
		document.getElementById('netAmount').value 	= parseFloat(sumOfItemAmount*1-discountAmount).toFixed(2);		

//		if(document.getElementById('docNo').value.substring(0,3)=="BCS") {
//			document.getElementById('payAmount').value = document.getElementById('netAmount').value
//			document.getElementById("refNo").value = "ST";
//		}else {
//			document.getElementById('payAmount').value = 0;
//			document.getElementById("refNo").value = "";
//		}		
	}
	
	document.getElementById('discountAmount').value = parseFloat(discountAmount).toFixed(2);
	document.getElementById('sumOfItemAmount').value = parseFloat(sumOfItemAmount).toFixed(2);
	
	return taxAmount;
}
function calSumOnly() {
	sumOfItemAmount = 0;
	discountAmount = 0;
	taxAmount = 0;
	
	if(document.getElementById('sumOfItemAmount').value!="") {
		sumOfItemAmount = parseFloat(document.getElementById('sumOfItemAmount').value);										
	}
	
	if(document.getElementById('discountAmount').value!="") {
		discountAmount = parseFloat(document.getElementById('discountAmount').value);										
	}	

	if(document.getElementById('taxAmount').value!="") {
		taxAmount = parseFloat(document.getElementById('taxAmount').value);										
	}	
			
	document.getElementById('totalAmount').value= parseFloat(sumOfItemAmount*1-discountAmount*1+taxAmount).toFixed(2);
	document.getElementById('netAmount').value 	= parseFloat(sumOfItemAmount*1-discountAmount*1+taxAmount).toFixed(2);
	
//	if(document.getElementById('docNo').value.substring(0,3)=="BCS") {
//		document.getElementById('payAmount').value = document.getElementById('netAmount').value
//		document.getElementById("refNo").value = "ST";
//	}else {
//		document.getElementById('payAmount').value = 0;
//		document.getElementById("refNo").value = "";
//	}	
	
}
function dataToPayAmountOLD() {
	//alert("datatopay");
	var mySelect = document.getElementById("preDocNo");
	for(var i=0; i<mySelect.options.length; i++) {
		if(mySelect.options[i].selected==true && mySelect.options[i].value=="BCS-") {
			document.getElementById('payAmount').value = document.getElementById('netAmount').value;					
			break;
		}else {
			document.getElementById('payAmount').value = 0;
		}
	}	
}

function dataToPayAmount() {
	
	var docNo = document.getElementById("docNo").value;
	if(docNo!=null && docNo.length>0) {

//		if(docNo.substring(0,3)=="BCS") {
//			document.getElementById("payAmount").value = document.getElementById("netAmount").value;
//			document.getElementById("refNo").value = "ST";
//		}else {
//			document.getElementById("payAmount").value = "0"
//			document.getElementById("refNo").value = "";
//		}					
	}
}

function calSumAmount() {
	sumOfAmount = 0;
	for(var i=1; i<=50; i++) {					
//		alert(document.getElementById('amount'+i));	
		if(document.getElementById('amount'+i)!=null) {			
			sumOfLineItemAmount[i]=document.getElementById('amount'+i).value;		
			sumOfAmount = sumOfAmount*1+sumOfLineItemAmount[i]*1;
			
		}
		//sumOfAmount = sumOfAmount*1+sumOfLineItemAmount[i]*1;
	}
//	alert(sumOfAmount);
	return sumOfAmount;
}

function checkKey() {
	
	if (event.keyCode==13 || event.charCode==13) {
		alert("key Code= 13");
	}else { 
		alert("key Code ไม่ ใช่ enter");
	}	
}

function calTaxType(selectObj) {
	var sumOfItemAmount=0;
	if(document.getElementById('sumOfItemAmount').value!="") {
		sumOfItemAmount = parseFloat(document.getElementById('sumOfItemAmount').value);										
	}	
	// document.getElementById('taxNo').value!="" || document.getElementById('taxType').value<2)  && 
//	if(  sumOfItemAmount!="") {
		var sumOfItemAmount = document.getElementById('sumOfItemAmount').value;
		var taxRate = document.getElementById('taxRate').value;
			
		if(selectObj.selectedIndex==0) {
		//	alert('0');
			var vat = sumOfItemAmount*taxRate/100;
			
			document.getElementById('taxAmount').value  = parseFloat(vat).toFixed(2);		
			document.getElementById('totalAmount').value= parseFloat(sumOfItemAmount*1-discountAmount+vat*1).toFixed(2);
							
		}else if(selectObj.selectedIndex==1) {
		//	alert('1');
			var taxAmount = sumOfItemAmount-sumOfItemAmount/(1+taxRate/100);  
			document.getElementById('taxAmount').value  = parseFloat(taxAmount).toFixed(2);		
			document.getElementById('totalAmount').value= parseFloat(sumOfItemAmount).toFixed(2);

		}else if(selectObj.selectedIndex==2) {
		//	alert('2');
			document.getElementById('taxAmount').value  = parseFloat(0).toFixed(2);		
			document.getElementById('totalAmount').value= parseFloat(sumOfItemAmount).toFixed(2);			
		}
		
		document.getElementById('netAmount').value 	= document.getElementById('totalAmount').value ;
		
		//alert(document.getElementById('docNo').value.substring(0,3));
//		if(document.getElementById('docNo').value.substring(0,3)=="BCS") {
//			document.getElementById('payAmount').value 	= document.getElementById('totalAmount').value;
//		}else {
//			document.getElementById('payAmount').value  = parseFloat(0).toFixed(2);	
//		}	
//	}else {

//	}					
}

function changeCreditDay() {
	var statementDate = document.getElementById('statementDate').value;
	var creditDay = document.getElementById('creditDay').value; 
	
	if(statementDate!="") {
		document.getElementById('dueDate').value = nextDay(statementDate,creditDay);
	}else {
		var currentTime = new Date();
		var month =currentTime.getMonth()+1;
		var day = currentTime.getDate();
		var	year = currentTime.getFullYear();
		document.getElementById('statementDate').value = year + "-" + month + "-" + day;		
		document.getElementById('dueDate').value = nextDay(statementDate,creditDay);; 
	}	
}

function changeStatementDate() {
	var statementDate = document.getElementById('statementDate').value;
	var creditDay = document.getElementById('creditDay').value; 

	if(creditDay!="") {
		document.getElementById('dueDate').value = nextDay(statementDate,creditDay);
	}else {
		document.getElementById('dueDate').value = statementDate; 
	}
}

function nextDay(statementDate, creditDay) {
	var dateArray = statementDate.split('-');		
	day = dateArray[2];
	month = 1*dateArray[1]-1;
	year = dateArray[0];

	var nextDate = new Date();
	nextDate.setFullYear(year, month, day);
	nextDate.setDate(nextDate.getDate()+1*creditDay);
	
	return nextDate.getFullYear()+"-"+(nextDate.getMonth()*1+1)+"-"+nextDate.getDate(); 
}

function calCreditDay() {
	var currentTime = new Date();
	var month =currentTime.getMonth()+1;
	var day = currentTime.getDate();
	var	year = currentTime.getFullYear();
	
	if(document.getElementById('statementDate').value=="") {
		document.getElementById('statementDate').value = year + "-" + month + "-" + day;		
	}

	if(document.getElementById('dueDate').value=="") {
		document.getElementById('dueDate').value = document.getElementById('statementDate').value;		
	}	

	var date1 = document.getElementById('statementDate').value;
	var date2 = document.getElementById('dueDate').value;
	
	document.getElementById('creditDay').value = days_between(date1, date2);
}

function days_between(date1, date2) {
	//example :date1 = 2010-12-1
	var d1 = date1.split('-');
	var d11 = new Date(d1[0], d1[1], d1[2]);
		
	var d2 = date2.split('-');
	var d22 = new Date(d2[0], d2[1], d2[2]);	
							
	var difference_ms = Math.abs(d11-d22);	
	var one_day = 1000*60*60*24;
		
	return Math.round(difference_ms/one_day);
}

function displayDate() {
	var currentTime = new Date();
	var month =currentTime.getMonth()+1;
	var day = currentTime.getDate();
	var	year = currentTime.getFullYear();

	if (document.getElementById('docDate').value=="")
		document.getElementById('docDate').value = year + "-" + month + "-" + day;

	if (document.getElementById('taxDate').value=="")
		document.getElementById('taxDate').value = document.getElementById('docDate').value;
	
	if (document.getElementById('statementDate').value=="") 
		document.getElementById('statementDate').value = document.getElementById('docDate').value;
	
	if (document.getElementById('dueDate').value=="")
		document.getElementById('dueDate').value = document.getElementById('docDate').value;

	if (document.getElementById('creditDay').value=="")
		document.getElementById('creditDay').value = "0";		
}

</script>

<script type="text/javascript" >
function modalWin(aa) {
	if (window.showModalDialog) {		
		window.showModalDialog(aa,"name","dialogTop:100px;dialogWidth:650px;dialogHeight:350px;center:yes");
	} else {		
		window.open(aa,'name','height=350,width=600,toolbar=no,directories=no,status=no,continued from previous linemenubar=no,scrollbars=no,resizable=no ,modal=yes');
	}
}
function modalWinItem(aa) {
	if (window.showModalDialog) {		
		window.showModalDialog(aa,"name","dialogTop:100px;dialogWidth:650px;dialogHeight:350px;center:yes");
	} else {		
		window.open(aa,'name','height=350,width=600,toolbar=no,directories=no,status=no,continued from previous linemenubar=no,scrollbars=no,resizable=no ,modal=yes');
	}
}
function modalWinDocNo(aa) {
	if (window.showModalDialog) {
		var docDate = document.getElementById('docDate').value;// 
		//alert(docDate);	
		aa = aa + "?docDate="+docDate;	
		window.showModalDialog(aa,"name","dialogTop:100px;dialogWidth:250px;dialogHeight:200px;center:yes");
	} else {		
		alert("b");
		window.open(aa,'name','height=350,width=600,toolbar=no,directories=no,status=no,continued from previous linemenubar=no,scrollbars=no,resizable=no ,modal=yes');
	}
}

function getDocDateToTaxDate() {
	document.getElementById('taxDate').value = document.getElementById('docDate').value;
}
</script>



</head>

<body onload="displayDate()" ><br />
<div id="wrapper">
	 
	<div id="menu"><ul id="nav"></ul></div>

	<div id="content">
		<div id="menuNav"><a href='<%=request.getContextPath() %>/Login.do?mode=check'>หน้าหลัก</a> 
		>> คลังพัสดุ - Store กลาง  >> จัดซื้อ
		>> <a href='<%=request.getContextPath() %>/apinvoice/po.do?mode=blank_po3'>4.บันทึกซื้อสินค้าและบริการ (เลือกจากใบ PO)</a>
		>> <html:link action="/apinvoice2.do?mode=showFind" >5.ดูรายการซื้อสินค้าและบริการ</html:link> 
		 
	</div><br />
			
			
			
	<div style="background: #ffffff;">
	<p align="center" id="titleIssueType">บันทึกใบสั่งซื้อ </p>
		<center><br />
			<div style="border: 1px solid;   width:200px; background: #ffc080" > 
 				คุณกำลังแก้ไขเอกสาร PO
			</div>
		</center>	
	<html:form action="/purchaseOrder.do?mode=update3" styleId="form1"  >	        

                <html:hidden property="creatorCode" value="${userName }" />
                
	<div id="userPw01">
	<fieldset>
		<legend><b>ข้อมูลใบสั่งซื้ออุปกรณ์, วัตถุดิบ</b></legend>
		   <center> 
		   <table border="0" >
		   		   
			<tr>
				<td width="160" align="right">เลขที่ใบสั่งซื้อ:</td>
				<td width="120">
					<html:text property="docNo" styleId="docNo" value="${po.docNo}" readonly="true" 
						errorKey="org.apache.struts.action.ERROR" style="width:115px"   />
					<html:errors property="docNo" />
				</td>
				<td width="10">
					
				</td>				
				<td width="120" align="right"> วันที่ออกเอกสาร:</td>
				<td ><html:text 	property="docDate" styleId="docDate" value="${po.docDate}" style="width:115px"
											errorKey="org.apache.struts.action.ERROR" readonly="false" 
											
											/>
								<html:errors property="docDate" />
				</td>
				<td width="10"></td>					
			</tr>
			<tr>
				<td width="160" align="right">ประเภทภาษี:</td>
				<td ><html:select property="taxType" value="${po.taxType}" styleId="taxType" 
																onchange='calTaxType(this)' style="width:115px">
									<html:option value="0">ภาษีแยกนอก</html:option>
									<html:option value="1">ภาษีรวมใน</html:option>
									<html:option value="2">ภาษีอัตราศูนย์</html:option>
								</html:select></td>
				<td width="20"></td>				
				<td align="right">แผนก:</td>
				<td width="140"><html:text property="departCode" value="${po.departCode}" styleId="departCode" 
								style="width:115px"  />
					<html:errors property="departCode" />
								</td>
				<td width="20"></td>
			</tr>			
			<tr>			
 				<td align="right">รหัสเจ้าหนี้:</td>
 				<td> 
 					<html:text property="apCode" value="${po.apCode}" styleId="apCode" readonly="false" style="width:115px"
 								onchange="getAP()"
						  		onblur="getAP()" 
 					/>
 					<html:errors property="apCode" />										 					 					 					 					
 				</td>
 				<td ><a href="#" target="name" onclick="modalWinItem('/ittl/apinvoice/ap.do?mode=apFind'); return false;">ค้น</a></td> 				
 				<td colspan="3">
 					&nbsp;<html:text property="apName" value="${po.tempMyDesc7}" size="40" styleId="apName" style="width:240px" readonly="true"/>
 				</td> 										 				 			
 			</tr>

 			<tr>
 				<td align="right">TTL PurchaseCode:</td>
 				<td colspan="4">
 					<html:text property="tempMyDesc2" value="${po.tempMyDesc2}" size="250" styleId="tempMyDesc2" style="width:387px" />
 				</td>
 				<td>(หมายเหตุ 2)</td> 				
 			</tr>
 			<tr>
 				<td align="right">เลขที่อ้างอิง พ.1:</td>
 				<td colspan="4">
 					<html:text property="tempMyDesc5" value="${po.tempMyDesc5}" size="250" styleId="tempMyDesc5" style="width:387px" />
 					<html:hidden property="tempMyDesc3" value="${po.tempMyDesc3}" styleId="tempMyDesc3"  />
 					<html:hidden property="tempMyDesc4" value="${po.tempMyDesc4}" styleId="tempMyDesc4"  />
 					<html:hidden property="tempMyDesc6" value="${po.tempMyDesc6}" styleId="tempMyDesc6"  />
 					<html:hidden property="tempMyDesc8" value="${po.tempMyDesc8}" styleId="tempMyDesc8"  />
 					
 				</td>
 				<td>(หมายเหตุ 5)</td> 				
 			</tr> 
 			<tr>
 				<td align="right">หมายเหตุ(PO):</td>
 				<td colspan="5">
 					<html:text property="myDescription" value="${po.myDescription}" size="250" styleId="myDescription" style="width:387px" />
 				</td> 				
 			</tr> 						 																 			 				 							
		</table>
		</center>
     </fieldset></div>
<div id="items"> 
     <fieldset>
     	<legend><b>รายการอุปกรณ์, วัตถุดิบ</b></legend>     	
     	      	     	
     	<p><!--<a href="#" onClick="addFormField(); return false;">
     			<img src="<%=request.getContextPath() %>/common/images/add.png" width="24" height="24" alt="Add" />เพิ่มรายการ
     		</a>     			   
     		--><input type="hidden" id="countId" value="${countId }">
     	</p>
     	
     	<center>	     		          	
		<table border="1" >
			<thead>
				<tr id="rHead">
					<th width="24">&nbsp;</th>
				  <th width="100" align="center">รหัสสินค้า</th>
				  <th width="10">&nbsp;</th>
				  <th width="270" align="center">ชื่อรายการ</th>
				  				

				  <th width="70"  align="center">หน่วยนับ</th>
				  
				  <th width="60"  align="center">จำนวน</th>
				  
				  <th width="60"  align="center">ราคาซื้อ</th>
				  				
				  <th width="60"  align="center">ส่วนลด</th>
				  				    
				  <th width="70"  align="center">จำนวนเงิน</th>
				  				  
				  <th width="10">&nbsp;</th>
				  			
				</tr>						
			</thead>
			
			<tbody id="inputs" >								 								
									     					     
					<logic:iterate id="aa"  indexId="id" collection="${po.bcPurchaseOrderSubs }">     		
						<tr id="r${id+1 }">
							<td valign="middle" >
								
									<a href='#' onClick="removeFormField('#r${id+1}',${id+1}); return false;">
										<img src="<%=request.getContextPath() %>/common/images/remove.png" width="24" height="24" alt="Remove" />
									</a>								
							</td>								
						  	<td>						  		
						  		<html:hidden property="ittl_rowOrderOfStkReq" value="${aa.ittl_rowOrderOfStkReq}" styleId="ittl_rowOrderOfStkReq${id+1}"  /> 
						  		<html:hidden property="lineNumber" value="${aa.lineNumber}" styleId="lineNumber${id+1}" />
						  		<html:text property="itemCode" value="${aa.itemCode}" styleId="itemCode${id+1}" size="15"						  				 
						  					style="align:right;width:100px"  />						  								  							  		
						  	</td>
						  	<td><!--<a href="#" target="name" onclick="modalWinItem('/ittl/apinvoice/apinvoice2.do?mode=moreItemsShow&lineNumber=${id+1 }'); return false;">ค้น</a>--></td>
							<td><html:text property="itemName" value="${aa.itemName}" maxlength="200" size="40" styleId="itemName${id+1}" />
															
							</td>												
							<td align="center"><html:select property="unitCode" value="${aa.unitCode}" styleId="unitCode${id+1}" style="width:60px" >
													<html:option value="PCS">Pcs.</html:option>
													<html:option value="007">Kgs.</html:option>
													<html:option value="008">Lbs.</html:option>
													<html:optionsCollection name="unitCodeList" label="name" value="code" />
											   </html:select>						
							</td>
							<td><html:text property="qty" value="${aa.qty}" size="7" styleId="qty${id+1}" onblur="calLineItem(${id+1});" style="text-align:right;width:60px"  />								
							</td>
							
							<td><html:text property="price" value="${aa.price}" size="7" styleId="price${id+1}" onblur="calLineItem(${id+1});" style="text-align:right;width:60px" />								
								</td>
							
							<td><html:text property="lineItemDiscountAmount" value="${aa.discountAmount}" size="7" styleId="lineItemDiscountAmount${id+1}" onblur="calLineItem(${id+1})"	style="text-align:right;width:60px"  />								
							</td>
												
							<td><html:text property="amount" value="${aa.amount}" styleId="amount${id+1}" size="10" onblur="calUnitPrice(${id+1})" style="text-align:right;width:80px" />
																												
								<html:hidden property="stkReqNo"  	value="${aa.stkReqNo}"  styleId="stkReqNo${id+1}" />
								<html:hidden property="confirmNo" 	value="${aa.confirmNo}" styleId="confirmNo${id+1}" />								
								<html:hidden property="lineItem_whCode" 		value="${aa.whCode}" 	 	styleId="lineItem_whCode${id+1}" />
								<html:hidden property="lineItem_shelfCode" 	value="${aa.shelfCode}" 	styleId="lineItem_shelfCode${id+1}" />																
								<html:hidden property="lineItem_departCode" 	value="${aa.departCode}" 	styleId="lineItem_departCode${id+1}" />
								<html:hidden property="lineItem_projectCode" 	value="${aa.projectCode}"  styleId="lineItem_projectCode${id+1}" />																						
								<html:hidden  property="lineItem_netAmount" 	value="" 	styleId="lineItem_netAmount${id+1}" />
								<html:hidden  property="lineItem_homeAmount" 	value="" 	styleId="lineItem_homeAmount${id+1}" />								
							</td>								
							
							<td>  </td>												
						</tr>
						<tr id="s${id+1 }">
							<td></td>								
						  	<td><html:errors property="itemCode${id+1}" /></td>
						  	<td></td>
							<td>
								<html:text property="myDescriptionItemName" value="${aa.myDescription}" maxlength="200" size="40" styleId="myDescription${id+1}" />
								
								<html:errors property="itemName${id+1}" />
							</td>												
							<td align="center"></td>
							<td><html:errors property="qty${id+1}" /></td>							
							<td><html:errors property="price${id+1}" /></td>							
							<td><html:errors property="lineItemDiscountAmount${id+1}" /></td>												
							<td><html:errors property="amount${id+1}" /></td>															
							<td></td>						
						</tr>																																		
					</logic:iterate>										
																								
			</tbody>					
		</table>
		</center><br/>  
			
		<!--<font size='2'>หมายเหตุ : <font color="red">Item ที่ลบได้ </font>คือข้อมูลที่เพิ่มเข้าไปใหม่</font>
		
		
     --></fieldset>
 	</div>    
 	<div id="userPw01">
	<fieldset>
		
		   <center> 
		   <table border="0" >
			<tr>
				<td align="right">โครงการ:</td>
				<td><html:select property="projectCode" value="${po.projectCode }" styleId="projectCode" style="width:90px">
 						<html:option value=""></html:option>
						<html:optionsCollection name="projectList" label="code" value="code" />
					</html:select>
					
				</td>
				<td>&nbsp;</td>			
 				<td align="right">รหัสผู้ติดต่อ:</td>
 				<td width="90px">&nbsp; 				
 				</td>
 				<td ></td>				 				 				
 				<td align="right">ยอดรวมมูลค่าสินค้า:</td>
 				<td><html:text property="sumOfItemAmount" value="${po.sumOfItemAmount}" styleId="sumOfItemAmount" onchange="calTaxAmount();" style="text-align:right;width:90px" />
					<html:errors property="sumOfItemAmount" />
 				
 					</td>
 				<td ></td>	
 			</tr>		   													
			<tr>
				<td align="right">เครดิต(วัน):</td>
 				<td>
					 					
 				</td>
				<td ></td>			
 				<td align="right">การจัดสรร:</td>
 				<td>
 					 
					
 				</td>
 				<td ></td>				 				 				
 				<td align="right">ส่วนลดบาท:</td>
 				<td>
 					<html:text property="discountAmount" value="${po.discountAmount}" styleId="discountAmount" onchange="calTaxAmount();" style="text-align:right;width:90px" />
					<html:errors property="discountAmount" />
 					
 				</td>
 				<td ></td>	
 			</tr>
 			<tr>
 				<td align="right">เอกสารหมดอายุภายใน:</td>
 				<td> 					
 				</td>
 				<td ></td>
 				<td align="right">วันที่หมดอายุ:</td>
 				<td>
 															 				
 				</td>
 				<td ></td>
 				<td align="right">ภาษีมูลค่าเพิ่ม:</td>
 				<td>
 					<html:text property="taxAmount" value="${po.taxAmount}" styleId="taxAmount" onchange="calSumOnly();" style="text-align:right;width:90px" />
					<html:errors property="taxAmount"/> 					
 				</td>
 				<td ></td> 				 				 				
 			</tr>
 			<tr>
				<td align="right">ระยะเวลาขนส่ง:</td>
				<td>
										
				</td>
 				<td ></td>
 				<td align="right">กำหนดส่ง:</td>
 				<td>
 					
			 					 				
 				</td>
 				<td ></td> 				
 				<td align="right">มูลค่ารวมภาษี:</td>
 				<td> 					
 					<html:text property="totalAmount" value="${po.totalAmount}" styleId="totalAmount" style="text-align:right;width:90px"  />
					<html:errors property="totalAmount" />	 					
 				</td>
 					
 				<td ></td>	 				 			 				 			 				 				
 			</tr>
 			<tr>
 				<td align="right">เงื่อนไขการรับสินค้า:</td>
 				<td>
 					 					
 				</td>
 				<td ></td>
 				<td align="right">อัตราภาษีมูลค่าเพิ่ม:</td>
 				<td> 					
 					<html:hidden property="taxRate" value="${po.taxRate}" styleId="taxRate"  />
					


 				</td>
 				<td ></td> 				
 				<td align="right">มูลค่าสินค้ายกเว้นภาษี:</td>
 				<td> 					
 					<html:text property="exceptTaxAmount" value="${po.exceptTaxAmount}" styleId="exceptTaxAmount"  style="text-align:right;width:90px" />
 					<html:errors property="exceptTaxAmount" />
					 					
 				</td>
 				<td ></td>	 				 			 				 			 				 				
 			</tr> 			 				 	
 			<tr>
 				<td align="right">รหัสสกุลเงิน:</td>
 				<td>
 				
					<html:select property="currencyCode" value="${po.currencyCode}" style="width:90px">						
						<html:option value="BAHT">บาท</html:option>						
					</html:select> 				
 				 					
 				</td>
 				<td ></td>	

 				<td align="right">อัตราแลกเปลี่ยน:</td>
 				<td> 					
 					<html:hidden property="exchangeRate" value="${po.exchangeRate}" styleId="exchangeRate"   />
					

 					
 					 
 				</td>
 				<td ></td>	

 				<td align="right">มูลค่าสุทธิ:</td>
 				<td>
 					<html:text property="netAmount" value="${po.netAmount}" styleId="netAmount" onchange="dataToPayAmount();" style="text-align:right;width:90px"  />
					<html:errors property="netAmount" /> 					
 					</td>
 				<td ></td>	
 			</tr> 			 				 							
		</table>
		</center>   
     </fieldset></div>
	      	
 	<table border="0" align="center" width="100%">
 		<tr>
 			<td align="center" ><html:submit value="บันทึกใบสั่งซื้อ " onclick="return confirm('ยืนยัน ?');" /></td>
 			<td align="center" ></td>
			<td align="center" ><html:button  value="กลับไปรายการเมนู" property="show1" 
 			onclick="gotoMenu()"  /></td> 			
 		</tr>
 	</table>    	    	    	
    </html:form><br>
    </div>

<script type="text/javascript">
function toUnicode(elmnt,content){
	//ที่ element นั้นต้องใส่ tabindex ด้วย
    if (content.length==elmnt.maxLength){
    	
      next=elmnt.tabIndex;
//      alert(next);
      if (next<document.forms[0].elements.length){
        document.forms[0].elements[next].focus();
       // return false;
    }
  }
}
</script>

<script type="text/javascript">

	for(var i=1; i<=15; i++) {
		
		var item = document.getElementById("itemCode"+i).value;
		//alert(item+'=>'+i);
		if(item=="") {
			idArray[i] = 0;
		}else {
			idArray[i] = 1;
		}		
	}
	
function refreshForm() {
	var lAddr = document.getElementById("localAddr").value;
	var lPort = document.getElementById("localPort").value;
	var ctPath = document.getElementById("contextPath").value;
	var docNo = document.getElementById("docNo").value
	window.location = "http://"+lAddr+":"+lPort+ctPath+"/StkReq.do?mode=edit&docNo="+docNo;	
}
function gotoMenu() {
	var lAddr = document.getElementById("localAddr").value;
	var lPort = document.getElementById("localPort").value;
	var ctPath = document.getElementById("contextPath").value;
	window.location = "http://"+lAddr+":"+lPort+ctPath+"/Login.do?mode=check";
}
</script>
<input type="hidden" value="<%=request.getLocalAddr() %>" id="localAddr">
<input type="hidden" value="<%=request.getLocalPort() %>" id="localPort">
<input type="hidden" value="<%=request.getContextPath() %>" id="contextPath">

<!-- 
<a href="#" class="add"><img src="add.png" width="24" height="24" alt="add" title="add input" /></a> 
<a href="#" class="reset"><img src="reset.png" width="24" height="24" alt="reset" /></a>
 -->
 
 </div>
 </div>
 
</body>
</html:html>